package ControlLayer;

import java.sql.Date;
import java.util.ArrayList;

import DBLayer.*;
import ModelLayer.*;



public class CtrMaterial {
	
	BDMaterial dbMaterial;
	
	public CtrMaterial()
	{
		dbMaterial = new BDMaterial();
	}

	
	
	
	public ArrayList<Material> getAllMaterials()
	{
		return dbMaterial.getAllMaterials();
	}
	
	
	
	public Material findMaterial(int materialId) 
	{
		return dbMaterial.findMaterial(materialId);
	}	
	
	
	public int deleteMaterial(int materialId)
	{
		return dbMaterial.deleteMaterial(materialId);
	}
	
	
	public int updateMaterial(int materialId, String name, String type)
	{
		Material material = new Material(materialId, name, type);
		return dbMaterial.updateMaterial(material);
	}
	
	public void insertNewMaterial(int materialId, String name, String type)
    {    
      Material materialObj = new Material();
    
     materialObj.setMaterialId(materialId);
     materialObj.setMaterialName(name);
     materialObj.setMaterialType(type);

         try{
          DbConnection.startTransaction();
          
          BDMaterial dbMaterial = new BDMaterial();
          dbMaterial.insertMaterial(materialObj);
          DbConnection.commitTransaction();
         }
         catch(Exception e)
         {
             DbConnection.rollbackTransaction();
         }
    }
	
}
